package net.jiastudy.web.rest.controller.project;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import net.jiastudy.biz.project.entity.DeptProjectReport;
import net.jiastudy.biz.project.entity.DeptProjectReportMoneySchedule;
import net.jiastudy.biz.project.entity.DeptProjectReportWorkSchedule;
import net.jiastudy.biz.project.service.DeptProjectReportService;
import net.jiastudy.core.base.BaseController;
import net.jiastudy.core.common.validgroup.Create;
import net.jiastudy.core.common.validgroup.Update;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/dept_project/{projectId}/dept_project_report")
@Api(value = "DeptProjectReportController  部门项目报表")
public class DeptProjectReportController extends BaseController {
	@Resource
	private DeptProjectReportService reportService;
	
	@RequestMapping(method = RequestMethod.POST)
	@ApiOperation(value = "新增", notes = "")
	public DeptProjectReport create(@PathVariable Long projectId, @Validated({ Create.class }) @RequestBody DeptProjectReport report) {
		report.setProjectId(projectId);
		return reportService.createReport(report);
	}
	
	@RequestMapping(path = "/{id}", method = RequestMethod.PUT)
	@ApiOperation(value = "编辑")
	public DeptProjectReport edit(@PathVariable @ApiParam(name = "id", required = true) Long id,
			@Validated({ Update.class }) @RequestBody DeptProjectReport report) {
		report.setId(id);
		return reportService.updateReport(report);
	}

	@RequestMapping(path = "/{id}", method = RequestMethod.POST)
	@ApiOperation(value = "删除")
	public Boolean delete(@PathVariable @ApiParam(name = "id", required = true) Long id) {
		return reportService.deleteReport(id);
	}
	
	@RequestMapping(path = "/{reportId}/work_schedule/{id}", method = RequestMethod.PUT)
	@ApiOperation(value = "编辑工作进度")
	public DeptProjectReportWorkSchedule editWorkSchedule(@PathVariable @ApiParam(name = "id", required = true) Long id,
			@Validated({ Update.class }) @RequestBody DeptProjectReportWorkSchedule workSchedule) {
		workSchedule.setId(id);
		return reportService.updateWorkSchedule(workSchedule);
	}
	
	@RequestMapping(path = "/{reportId}/money_schedule/{id}", method = RequestMethod.PUT)
	@ApiOperation(value = "编辑金额进度")
	public DeptProjectReportMoneySchedule editMoneySchedule(@PathVariable @ApiParam(name = "id", required = true) Long id,
			@Validated({ Update.class }) @RequestBody DeptProjectReportMoneySchedule moneySchedule) {
		moneySchedule.setId(id);
		return reportService.updateMoneySchedule(moneySchedule);
	}
	
	@RequestMapping(path = "/{id}", method = RequestMethod.GET)
	@ApiOperation(value = "获取报表")
	public DeptProjectReport get(@PathVariable Long id) {
		return reportService.getById(id);
	}

	@RequestMapping(path = "/last_report", method = RequestMethod.GET)
	@ApiOperation(value = "获取报表")
	public DeptProjectReport getLastReport(@PathVariable Long projectId) {
		return reportService.getLastReport(projectId);
	}
}
